home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / trackfld.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  230 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *trackfld_scroll;
  14. unsigned char *trackfld_scroll2;
  15. static int flipscreen;
  16.  
  17.  
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23.   Track 'n Field has one 32x8 palette PROM and two 256x4 lookup table PROMs
  24.   (one for characters, one for sprites).
  25.   The palette PROM is connected to the RGB output this way:
  26.  
  27.   bit 7 -- 220 ohm resistor  -- BLUE
  28.         -- 470 ohm resistor  -- BLUE
  29.         -- 220 ohm resistor  -- GREEN
  30.         -- 470 ohm resistor  -- GREEN
  31.         -- 1  kohm resistor  -- GREEN
  32.         -- 220 ohm resistor  -- RED
  33.         -- 470 ohm resistor  -- RED
  34.   bit 0 -- 1  kohm resistor  -- RED
  35.  
  36. ***************************************************************************/
  37. void trackfld_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  38. {
  39.     int i;
  40.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  41.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  42.  
  43.  
  44.     for (i = 0;i < Machine->drv->total_colors;i++)
  45.     {
  46.         int bit0,bit1,bit2;
  47.  
  48.  
  49.         /* red component */
  50.         bit0 = (*color_prom >> 0) & 0x01;
  51.         bit1 = (*color_prom >> 1) & 0x01;
  52.         bit2 = (*color_prom >> 2) & 0x01;
  53.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  54.         /* green component */
  55.         bit0 = (*color_prom >> 3) & 0x01;
  56.         bit1 = (*color_prom >> 4) & 0x01;
  57.         bit2 = (*color_prom >> 5) & 0x01;
  58.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  59.         /* blue component */
  60.         bit0 = 0;
  61.         bit1 = (*color_prom >> 6) & 0x01;
  62.         bit2 = (*color_prom >> 7) & 0x01;
  63.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  64.  
  65.         color_prom++;
  66.     }
  67.  
  68.     /* color_prom now points to the beginning of the lookup table */
  69.  
  70.  
  71.     /* sprites */
  72.     for (i = 0;i < TOTAL_COLORS(1);i++)
  73.         COLOR(1,i) = *(color_prom++) & 0x0f;
  74.  
  75.     /* characters */
  76.     for (i = 0;i < TOTAL_COLORS(0);i++)
  77.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  78. }
  79.  
  80.  
  81.  
  82. /***************************************************************************
  83.  
  84.   Start the video hardware emulation.
  85.  
  86. ***************************************************************************/
  87. int trackfld_vh_start(void)
  88. {
  89.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  90.         return 1;
  91.     memset(dirtybuffer,1,videoram_size);
  92.  
  93.     /* TracknField has a virtual screen twice as large as the visible screen */
  94.     if ((tmpbitmap = osd_create_bitmap(2 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  95.     {
  96.         free(dirtybuffer);
  97.         return 1;
  98.     }
  99.  
  100.     return 0;
  101. }
  102.  
  103.  
  104.  
  105. /***************************************************************************
  106.  
  107.   Stop the video hardware emulation.
  108.  
  109. ***************************************************************************/
  110. void trackfld_vh_stop(void)
  111. {
  112.     free(dirtybuffer);
  113.     osd_free_bitmap(tmpbitmap);
  114. }
  115.  
  116.  
  117.  
  118. WRITE_HANDLER( trackfld_flipscreen_w )
  119. {
  120.     if (flipscreen != (data & 1))
  121.     {
  122.         flipscreen = data & 1;
  123.         memset(dirtybuffer,1,videoram_size);
  124.     }
  125. }
  126.  
  127.  
  128.  
  129. /***************************************************************************
  130.  
  131.   Draw the game screen in the given osd_bitmap.
  132.   Do NOT call osd_update_display() from this function, it will be called by
  133.   the main emulation engine.
  134.  
  135. ***************************************************************************/
  136. void trackfld_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  137. {
  138.     int offs;
  139.  
  140.  
  141.     /* for every character in the Video RAM, check if it has been modified */
  142.     /* since last time and update it accordingly. */
  143.     for (offs = videoram_size - 1;offs >= 0;offs--)
  144.     {
  145.         if (dirtybuffer[offs])
  146.         {
  147.             int sx,sy,flipx,flipy;
  148.  
  149.  
  150.             dirtybuffer[offs] = 0;
  151.  
  152.             sx = offs % 64;
  153.             sy = offs / 64;
  154.             flipx = colorram[offs] & 0x10;
  155.             flipy = colorram[offs] & 0x20;
  156.             if (flipscreen)
  157.             {
  158.                 sx = 63 - sx;
  159.                 sy = 31 - sy;
  160.                 flipx = !flipx;
  161.                 flipy = !flipy;
  162.             }
  163.  
  164.             drawgfx(tmpbitmap,Machine->gfx[0],
  165.                     videoram[offs] + 4 * (colorram[offs] & 0xc0),
  166.                     colorram[offs] & 0x0f,
  167.                     flipx,flipy,
  168.                     8*sx,8*sy,
  169.                     0,TRANSPARENCY_NONE,0);
  170.         }
  171.     }
  172.  
  173.  
  174.     /* copy the temporary bitmap to the screen */
  175.     {
  176.         int scroll[32];
  177.  
  178.  
  179.         if (flipscreen)
  180.         {
  181.             for (offs = 0;offs < 32;offs++)
  182.                 scroll[31-offs] = 256 - (trackfld_scroll[offs] + 256 * (trackfld_scroll2[offs] & 1));
  183.         }
  184.         else
  185.         {
  186.             for (offs = 0;offs < 32;offs++)
  187.                 scroll[offs] = -(trackfld_scroll[offs] + 256 * (trackfld_scroll2[offs] & 1));
  188.         }
  189.  
  190.         copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  191.     }
  192.  
  193.  
  194.     /* Draw the sprites. */
  195.     for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
  196.     {
  197.         int sx,sy,flipx,flipy;
  198.  
  199.  
  200.         sx = spriteram[offs] - 1;
  201.         sy = 240 - spriteram_2[offs + 1];
  202.         flipx = ~spriteram_2[offs] & 0x40;
  203.         flipy = spriteram_2[offs] & 0x80;
  204.         if (flipscreen)
  205.         {
  206.             sy = 240 - sy;
  207.             flipy = !flipy;
  208.         }
  209.  
  210.         /* Note that this adjustement must be done AFTER handling flipscreen, thus */
  211.         /* proving that this is a hardware related "feature" */
  212.         sy += 1;
  213.  
  214.         drawgfx(bitmap,Machine->gfx[1],
  215.                 spriteram[offs + 1],
  216.                 spriteram_2[offs] & 0x0f,
  217.                 flipx,flipy,
  218.                 sx,sy,
  219.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  220.  
  221.         /* redraw with wraparound */
  222.         drawgfx(bitmap,Machine->gfx[1],
  223.                 spriteram[offs + 1],
  224.                 spriteram_2[offs] & 0x0f,
  225.                 flipx,flipy,
  226.                 sx-256,sy,
  227.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  228.     }
  229. }
  230.